﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SCCN.BLL;
using SCCN.DAL;
using SCCN.Utility;
using System.Text;

/// <summary>
/// CreateArticleLeft 的摘要说明
/// </summary>
public class CreateArticleLeft : CreatePage
{
    public CreateArticleLeft()
    {
    }

    /// <summary>
    /// 生成
    /// </summary>
    /// <returns></returns>
    public static bool Create()
    {
        string path = ReaderTemplate("~/template/articleleft.html");
        string content = Fun_Rapalce_Tag(path);
        try
        {
            CreateHTMLHelper.CreateFile(HttpContext.Current.Server.MapPath("~/articleleft.shtml"), CreatePage.encode, content);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return true;
    }

    /// <summary>
    /// 替换页面标签
    /// </summary>
    /// <param name="content"></param>
    /// <returns></returns>
    public static string Fun_Rapalce_Tag(string content)
    {
        //标签存放字典
        Dictionary<string, string> dict = new Dictionary<string, string>();
        dict.Add("{$Article_Choice$}", Article_Choice());
        dict.Add("{$Article_Hot$}", Article_Hot());
        dict.Add("{$Article_Tag$}", Article_Tag());
        dict.Add("{$Today_Styling$}", Today_Styling());
        dict.Add("{$Cool_Magazine$}", Cool_Magazine());
        content = CreateHTMLHelper.ReplaceTag(dict, content);
        return content;
    }

    /// <summary>
    /// 今日造型
    /// </summary>
    /// <returns></returns>
    public static string Today_Styling()
    {
        StringBuilder str = new StringBuilder();
        AdvertisementBLL bllAdvertisement = AdvertisementBLL.getInstance();
        AdSpaceBLL bllAdSpace = AdSpaceBLL.getInstance();
        SC_AdSpace objAdSpace = bllAdSpace.GetAdSpaceByName("今日造型");
        List<SC_Advertisement> list = bllAdvertisement.GetAdvertisementByAdSpaceId(objAdSpace.Id);
        foreach (SC_Advertisement var in list)
        {
            str.Append("<div class=\"bt-left-ts mt10\">");
            str.Append("</div>");
            str.Append("<div class=\"left-ts-body\">");
            str.Append("<a href=\"" + var.TargetUrl + "\">");
            str.Append("<img src=\"" + var.PicSrc + "\" alt=\"" + var.AdName + "\" /></a>");
            str.Append("</div>");
        }
        return str.ToString();
    }

    /// <summary>
    /// cool杂志
    /// </summary>
    /// <returns></returns>
    public static string Cool_Magazine()
    {
        StringBuilder str = new StringBuilder();
        AdvertisementBLL bllAdvertisement = AdvertisementBLL.getInstance();
        AdSpaceBLL bllAdSpace = AdSpaceBLL.getInstance();
        SC_AdSpace objAdSpace = bllAdSpace.GetAdSpaceByName("SoCooL杂志");
        List<SC_Advertisement> list = bllAdvertisement.GetAdvertisementByAdSpaceId(objAdSpace.Id);
        str.Append("<div class=\"bt_mag\">");
        str.Append("</div>");
        str.Append("<div class=\"mag_slide\">");
        str.Append("<ul class=\"slide_nav\">");
        int i = 0;
        foreach (SC_Advertisement var in list)
        {
            if (i == 0)
            {
                str.Append("<li><a href=\"" + var.TargetUrl + "\" class=\"current\">01</a></li>");
            }
            else
            {
                str.Append("<li><a href=\"" + var.TargetUrl + "\" >01</a></li>");
            }
            i++;
        }
        str.Append("</ul>");
        str.Append("<div class=\"slide_box\">");
        foreach (SC_Advertisement var in list)
        {
            str.Append("<a href=\"" + var.AdName + "\">");
            str.Append("<img src=\"" + var.PicSrc + "\" alt=\"\" /></a> ");
        }
        str.Append("</div>");
        str.Append("</div>");
        return str.ToString();
    }

    /// <summary>
    /// 文章精选
    /// </summary>
    /// <returns></returns>
    public static string Article_Choice()
    {
        StringBuilder str = new StringBuilder();
        ArticleBLL bllArticle = ArticleBLL.getInstance();
        List<SC_Article> list = bllArticle.GetArticleChoice();
        foreach (SC_Article var in list)
        {
            str.Append("<li><a href=\"" + var.CreateUrl + "\">" + var.Tag + "</a></li>");
        }
        return str.ToString();
    }

    /// <summary>
    /// 文章热门
    /// </summary>
    /// <returns></returns>
    public static string Article_Hot()
    {
        StringBuilder str = new StringBuilder();
        ArticleBLL bllArticle = ArticleBLL.getInstance();
        List<SC_Article> list = bllArticle.GetArticleHot();
        foreach (SC_Article var in list)
        {
            str.Append("<li><a href=\"" + var.CreateUrl + "\">" + var.Tag + "</a></li>");
        }
        return str.ToString();
    }

    /// <summary>
    /// 文章Tag
    /// </summary>
    /// <returns></returns>
    public static string Article_Tag()
    {
        StringBuilder str = new StringBuilder();
        ArticleBLL bllArticle = ArticleBLL.getInstance();
        List<SC_Article> list = bllArticle.GetArticleTag();
        foreach (SC_Article var in list)
        {
            str.Append("<li><a href=\"" + var.CreateUrl + "\">" + var.Tag + "</a></li>");
        }
        return str.ToString();
    }
}